{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
	<div class="layui-card-header">添加会员</div>
    <div class="layui-card-body">
        <form class="layui-form form-horizontal" action="{:url('admin/member/add')}" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" lay-verify="username" autocomplete="off" placeholder="用户名" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">手机号</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6-20位字符，可由英文、数字及标点符号组成</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password_confirm" lay-verify="password_confirm" autocomplete="off" placeholder="确认密码" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">请再次输入您的密码</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">真实姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="nickname" lay-verify="realname" autocomplete="off" placeholder="真实姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <select name="roleid" lay-filter="sex">
                        <option value="1" {{#  if(data.sex == 1){ }}selected{{#  } }}>男</option>
                        <option value="2" {{#  if(data.sex == 2){ }}selected{{#  } }}>女</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-inline">
                    <select name="roleid" lay-filter="roleid">
                        <option value="1">普通用户</option>
                        <option value="2">一级管理</option>
                        <option value="4">二级管理</option>
                        <option value="3">志愿者</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">会员单位</label>
                <div class="layui-input-inline">
                    <select id="danwei" name="danwei" lay-filter="danwei">
                        <option value="0" >选择用户单位</option>
                        {volist name="fieldList" id="vo"}
                        <option value="{$vo}" >{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">会员支部</label>
                <div class="layui-input-inline">
                    <select id="zhibu" name="zhibu" lay-filter="zhibu">

                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn ajax-post" lay-submit="" lay-filter="*" target-form="form-horizontal">立即提交</button>
                </div>
            </div>
        </form>
        <div class="layui-form-item" style="margin-left: 100px;margin-top: -52px;">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" onClick="javascript :history.back(-1);">返回</button>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/admin/js/common.js"></script>
<script>
    //重新渲染表单
    function renderForm(){
        layui.use('form', function(){
            var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
            form.render();
        });
    }

    layui.use(['jquery', 'form'], function() {
        var $ = layui.jquery;
        var form = layui.form;

        form.on('select(danwei)', function (data) {
            console.log(data.value);
            $.ajax({
                url:"{:url('admin/member/getZhi')}",
                type:"post",
                data:{'value':data.value},
                success:function (e) {
                    var data = e.data;
                    var html = "<option value=''>请选择支部</option>";
                    for(var i=0;i<data.length;i++){
                        html += '<option value="'+data[i]+'">'+data[i]+'</option>';
                    }
                    $("#zhibu").html(html);
                    renderForm();
                }
            })
        });

    });
</script>
{/block}